<!DOCTYPE html>
<html>
<head>
    <title>财务缴款单据打印</title>
<#include "../common/common.ftl"/>
</head>
<body style="overflow-y: hidden;">
<div class="layui-fluid">
    <blockquote class="layui-elem-quote layui-bg-white">
        单据打印【姓名：<span class="jmdf-color-red">${(contract.name)!}</span>】【协议编号：<span
            class="jmdf-color-red">${(contract.contractCode)!}</span>】
    </blockquote>
    <div class="layui-row layui-col-space15 handInMoney">
        <div class="layui-col-lg5 layui-col-md5">
            <div class="layui-card">
            <#if (contract.financeSettleStatus !=2)>
                <div class="layui-card-header">1.登记缴款信息</div>
                <div class="layui-card-body">
                    <button class="layui-btn layui-btn-fluid setHandInMoney" contractId="${(contract.id)!}">登记缴款信息</button>
                </div>
            </#if>
            <#if (contract.finalMoney gt 0 && contract.financeSettleStatus ?? && contract.financeSettleStatus ==1  && contract.daffStatus ?? && contract.daffStatus ==1 )>
                <div class="layui-card-header">2.设置档案状态</div>
                <div class="layui-card-body">
                    <button class="layui-btn layui-btn-fluid setDaffStatus" contractId="${(contract.id)!}">设置为档案已发放
                    </button>
                </div>
            </#if>
                <div class="layui-card-header">2.设置结清状态：
                <#if contract.financeSettleStatus == 1><span class="jmdf-color-red">未结清</span></#if>
                <#if contract.financeSettleStatus == 2><span class="jmdf-color-green">已结清</span></#if>
                <#if contract.financeSettleStatus == 3><span class="jmdf-color-blue">部分结清</span></#if>
                </div>
                <div class="layui-card-body">
                    <button class="layui-btn layui-btn-fluid setFinanceSettleStatus" contractId="${(contract.id)!}">
                        设置结清状态
                    </button>
                </div>
            </div>
            <form class="layui-form">
                <div class="layui-card">
                    <div class="layui-card-header">
                        <span class="jmdf-color-red">注：需缴款的款项结清后才可显示所有房源！
                        点击房源可改变《户型清单》数据！</span>
                    </div>
                    <div class="layui-card-body">
                        <table class="layui-table">
                            <tr>
                                <th style="text-align: center;min-width: 100px">所在小区</th>
                                <th style="text-align: center;min-width: 80px">户号</th>
                                <th style="text-align: center;min-width: 80px">产权人</th>
                                <th style="text-align: center;min-width: 60px">操作</th>
                            </tr>
                        <#if (houseList??)>
                            <#list houseList as house>
                                <tr>
                                    <td style="text-align: center;">${house.azProject.projectName}</td>
                                    <td style="text-align: center;">${house.houseNumStr}</td>
                                    <td style="text-align: center;">
                                        <#assign buyHousePersonHouseList=(buyHousePersonHouseMap[house.id?c])! />
                                        <#if buyHousePersonHouseList?? && buyHousePersonHouseList?size != 0>
                                                <#list buyHousePersonHouseList as buyHousePersonHouse>
                                                    ${(buyHousePersonHouse.name)!}<br/>
                                                </#list>
                                            <#else>
                                                ${(contract.name)!}
                                        </#if>
                                    </td>
                                    <td style="text-align: center;">
                                        <input type="checkbox" name="houseId" value="${(house.id)!}" lay-skin="primary"
                                               lay-filter="filter"/>
                                    </td>
                                </tr>
                            </#list>
                        </#if>
                        <#if (carLotList??)>
                            <#list carLotList as carLot>
                                <tr>
                                    <td style="text-align: center;">${carLot.azProject.projectName}</td>
                                    <td style="text-align: center;">${carLot.houseNum}</td>
                                    <td style="text-align: center;">
                                        <#assign buyHousePersonCarLotList=(buyHousePersonCarLotMap[carLot.id?c])! />
                                        <#if buyHousePersonCarLotList?? && buyHousePersonCarLotList?size != 0>
                                                <#list buyHousePersonCarLotList as buyHousePersonCarLot>
                                                ${(buyHousePersonCarLot.name)!}<br/>
                                                </#list>
                                            <#else>
                                                ${(contract.name)!}
                                        </#if>
                                    </td>
                                    <td style="text-align: center;">
                                        <input type="checkbox" name="carLotId" value="${(carLot.id)!}"
                                               lay-skin="primary" lay-filter="filter"/>
                                    </td>
                                </tr>
                            </#list>
                        </#if>
                        <#if (storageRoomList??)>
                            <#list storageRoomList as storageRoom>
                                <tr>
                                    <td style="text-align: center;">${storageRoom.azProject.projectName}</td>
                                    <td style="text-align: center;">${storageRoom.houseNumStr}</td>
                                    <td style="text-align: center;">
                                        <#assign buyHousePersonStorageRoomList=(buyHousePersonStorageRoomMap[storageRoom.id?c])! />
                                        <#if buyHousePersonStorageRoomList?? && buyHousePersonStorageRoomList?size != 0>
                                                <#list buyHousePersonStorageRoomList as buyHousePersonStorageRoom>
                                                    ${(buyHousePersonStorageRoom.name)!}<br/>
                                                </#list>
                                            <#else>
                                                ${(contract.name)!}
                                        </#if>
                                    </td>
                                    <td style="text-align: center;">
                                        <input type="checkbox" name="storageRoomId" value="${(storageRoom.id)!}"
                                               lay-skin="primary" lay-filter="filter"/>
                                    </td>
                                </tr>
                            </#list>
                        </#if>
                            <#if (shopHouseList??)>
                                <#list shopHouseList as shopHouse>
                                    <tr>
                                        <td style="text-align: center;">${shopHouse.azProject.projectName}</td>
                                        <td style="text-align: center;">${shopHouse.houseNumStr}</td>
                                        <td style="text-align: center;">
                                            <#assign buyHousePersonShopHouseList=(buyHousePersonShopHouseMap[storageRoom.id?c])! />
                                            <#if buyHousePersonShopHouseList?? && buyHousePersonShopHouseList?size != 0>
                                                    <#list buyHousePersonShopHouseList as buyHousePersonShopHouse>
                                                        ${(buyHousePersonShopHouse.name)!}<br/>
                                                    </#list>
                                                <#else>
                                                    ${(contract.name)!}
                                            </#if>
                                        </td>
                                        <td style="text-align: center;">
                                            <input type="checkbox" name="shopHouseId" value="${(shopHouse.id)!}"
                                                   lay-skin="primary" lay-filter="filter"/>
                                        </td>
                                    </tr>
                                </#list>
                            </#if>
                        </table>
                    </div>
                    <div class="layui-card-header">
                        <span class="jmdf-color-red">注：款项结清后才可显示所有房源！
                        点击房源可改变《户型清单》数据！</span>
                    </div>
                </div>
            </form>
        </div>
        <div class="layui-col-lg7 layui-col-md7">
            <div class="layui-card">
                <div class="layui-tab layui-tab-brief" id="finance">
                    <ul class="layui-tab-title">
                        <li class="layui-this refreshPDF" source="/pdf/print/houseTypeListPDF?contractId=${(contract.id)!}">交房通知书及户型清单</li>
                        <li class="printPDF" source="/pdf/print/settleVoucherPDF?contractId=${(contract.id)!}">结清凭证</li>
                    </ul>
                    <iframe id="printIframe" style="width: 100%;height: 730px;margin-top: 10px"></iframe>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script src="/layui/layui.js" charset="utf-8"></script>
<script>
    layui.config({
        base: '/modules/' //静态资源所在路径
    }).use(['jquery', 'form', 'layer', 'element', 'jmdf'], function () {
        var $ = layui.jquery, jmdf = layui.jmdf, form = layui.form, layer = layui.layer, element = layui.element;

        //封装打印链接调用方法
        function openPdf(source) {
            var url = source + "#toolbar=0";
            $("#printIframe").attr("src", url);
        }

        //选项卡点击时改变PDF链接
        $(".printPDF").click(function () {
            var source = $(this).attr("source");
            openPdf(source);
        });

        //页面初始化时，默认加载第一个选项卡
        openPdf($("#finance li").attr("source"));

        //监听checkbox按钮，随时触发改变PDF链接
        form.on('checkbox(filter)', function (data) {
            refreshPDF();
        });

        //选项卡第一个点击时触发
        $(".refreshPDF").click(function () {
            refreshPDF();
        });

        //刷新户型清单方法
        function refreshPDF() {
            var houseIdStr = "";
            var carLotIdStr = "";
            var storageRoomIdStr = "";
            var shopHouseIdStr = "";
            $("input:checkbox[name='houseId']:checked").each(function () {
                houseIdStr += $(this).val() + ",";
            });

            $("input:checkbox[name='carLotId']:checked").each(function () {
                carLotIdStr += $(this).val() + ",";
            });
            $("input:checkbox[name='storageRoomId']:checked").each(function () {
                storageRoomIdStr += $(this).val() + ",";
            });
            $("input:checkbox[name='shopHouseId']:checked").each(function () {
                shopHouseIdStr += $(this).val() + ",";
            });
            var source = "/pdf/print/houseTypeListPDF?contractId=${(contract.id)!}";
            if (houseIdStr.length > 0) {
                houseIdStr = houseIdStr.substring(0, houseIdStr.length - 1);
                source += "&houseIdStr=" + houseIdStr;
            }
            if (carLotIdStr.length > 0) {
                carLotIdStr = carLotIdStr.substring(0, carLotIdStr.length - 1);
                source += "&carLotIdStr=" + carLotIdStr;
            }
            if (storageRoomIdStr.length > 0) {
                storageRoomIdStr = storageRoomIdStr.substring(0, storageRoomIdStr.length - 1);
                source += "&storageRoomIdStr=" + storageRoomIdStr;
            }

            if (shopHouseIdStr.length > 0) {
                shopHouseIdStr = shopHouseIdStr.substring(0, shopHouseIdStr.length - 1);
                source += "&shopHouseIdStr=" + shopHouseIdStr;
            }
            openPdf(source);
        }

        //设置缴款金额
        $(".setHandInMoney").click(function () {
            jmdf.viewUpdate("handInMoneyRecordList?contractId=${(contract.id)!}", 80);
        });

        //设置结清状态
        $(".setDaffStatus").click(function () {
            layer.open({
                title: false,
                shade: 0.5,
                content: "确认设置为档案已发放状态吗？",
                btn: ['确定', '取消'],
                closeBtn: 0,
                btnAlign: 'c'
                ,
                yes: function (index) {
                    $.get("/business/daff/setDaffStatus", {
                        contractId: '${(contract.id)!}',
                        _time: new Date().getTime()
                    }, function (data) {
                        if (data.code == "0001") {//成功
                            layer.msg(data.message, {anim: 0, icon: 1, time: 500}, function () {
                                location.reload();
                            });
                        } else {//失败
                            layer.msg(data.message, {anim: 6, icon: 2, time: 3000});
                        }
                        layer.close(index);
                    });
                }
            });
        });

        //设置结清状态
        $(".setFinanceSettleStatus").click(function () {
            var money = ${(contract.shouldHandInMoney)!0} + ${(contract.handInMoney)!0};
            if (money < 0) {
                alert("该户尚未结清房款,请核对后再进行结算");
                jmdf.viewUpdate("setHouseSettleStatusList?contractId=${(contract.id)!}", 90);
            } else if (money >= 0) {
                var msg = '${(contract.financeSettleStatus)!0}' == 2 ? "未结清" : "全部结算";
                layer.open({
                    title: false,
                    shade: 0.5,
                    content: "确认设置为" + msg + "吗？",
                    btn: ['确定', '取消'],
                    closeBtn: 0,
                    btnAlign: 'c'
                    ,
                    yes: function (index) {
                        $.get("setFinanceSettleStatus", {
                            contractId: '${(contract.id)!}',
                            _time: new Date().getTime()
                        }, function (data) {
                            if (data.code == "0001") {//成功
                                layer.msg(data.message, {anim: 0, icon: 1, time: 500}, function () {
                                    location.reload();
                                });
                            } else {//失败
                                layer.msg(data.message, {anim: 6, icon: 2, time: 3000});
                            }
                            layer.close(index);
                        });
                    }
                });
            }
        })
    })
</script>
</html>
